package cathe

import (
	"context"
	"fmt"
	"github.com/go-redis/redis/v8"
	"log"
	"store/appconfig"
)

var Ctx = context.Background()
var Rdb *redis.Client

func Init() {
	redis1 := appconfig.Appconf.Redis
	redis2 := fmt.Sprintf("%s:%d", redis1.Host, redis1.Port)
	redis3 := redis1.Password
	Rdb = redis.NewClient(&redis.Options{
		Addr:     redis2,
		Password: redis3, // no password set
		DB:       0,      // use default DB
	})

	err := Rdb.Set(Ctx, "key", "value", 0).Err()
	if err != nil {
		panic(err)
	}
	log.Println("redis 连接成功")

}
